//using System;
//using System.Collections.Generic;
//using System.Linq;
////using System.Speech.Recognition;
//using Microsoft.Speech.AudioFormat;
//using Microsoft.Speech.Recognition;
//using Coding4Fun.Kinect.WinForm;
//using Microsoft.Kinect;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.GamerServices;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Input.Touch;
//using Microsoft.Xna.Framework.Media;
//using System.IO;
//using ParticleSample;

//namespace SpaceKinect
//{
//    public class Game1 : Microsoft.Xna.Framework.Game
//    {
//        //FIELDS
//        #region Structs + Enumerations

//        struct Bullet
//        {
//            public Vector3 position;
//            public Quaternion rotation;
//        }

//        struct Star
//        {
//            public Vector3 position;
//        }

//        enum CollisionType { None, Boundary, Target}

//        struct Powerup
//        {
//            public Texture2D enabled;
//            public Texture2D disabled;
//            public String Name;
//            public int Value;
//        }

//        #endregion
        
//        #region Numeric Game Variables

//        //Score from shooting targets
//        int targetScore = 0;
//        //Total score (targets + distance travelled)
//        int totalScore = 0;

//        //Width of the tunnel
//        int mapWidth = 10;
//        //Height of the tunnel
//        int mapHeight = 7;
//        //Used to generate continual tunnels
//        int nextTunnel = -100;

//        //Game Speed
//        float gameSpeed = 2.0f;

//        //No of targets generated when AddTargets() is called
//        int noOfTargets = 20;

//        //Speed of bullets (represents the time interval between shots; a larger number = slower firing rate) 
//        float firingspeed = 200;
//        //Default Weapon Speed
//        float DefaultFiringSpeed = 200;

//        //Number of destroyed targets between powerups
//        int DestroyedTargets = 0;

//        //Whether or not debugmode is on
//        bool debugmode = false;

//        //Old keyboard state. Used to detect key presses
//        KeyboardState oldstate = Keyboard.GetState();

//        //Spread of the stars
//        int starSpread = 4;             ///Default: 4
//        //No of stars in the map
//        int numberOfStars = 1000;       ///Default: 1,000
//        // How far away from the highway they are
//        int distanceAddition = 10;      ///Default: 10        

//        //Window width
//        int windowWidth = 1360;
//        //Window height
//        int windowHeight = 768;
//        #endregion

//        #region Other Game Declarations

//        //Random number generators
//        static Random rnd = new Random();
//        Random random = new Random(5);
        
//        //Graphics
//        GraphicsDeviceManager graphics;
//        SpriteBatch spriteBatch;
//        GraphicsDevice device;
//        //VertexBuffer (Used to store data on GPU; saves sending exactly the same data to the GPU each frame)
//        VertexBuffer mapVertexBuffer;
//        //Effects
//        Effect effect;

//        //Player ship object
//        Player player;

//        //Models
//        Model targetModel;
//        Model UFOModel;

//        //Textures
//        Texture2D sceneryTexture;
//        Texture2D bulletTexture;
//        Texture2D starTexture;
//        Texture2D barTexture;
//            //HUD bar
//        Texture2D bar_life;
//        Texture2D bar_health_enabled;
//        Texture2D bar_health_disabled;
//        Texture2D bar_health_end;
//        Texture2D bar_music_muted;
//        Texture2D bar_music_unmuted;

//        //Bounding Box of map
//        BoundingBox mapBox;

//        //Matrices
//        Matrix viewMatrix;
//        Matrix projectionMatrix;
//       //Matrix worldMatrix;

//        //Vectors
//        Vector3 cameraPosition;
//        Vector3 cameraUpDirection;
//        Vector3 lightDirection = new Vector3(3, -2, 5);

//        //Position and rotation of ship
//        //Vector3 shipPosition;
//        //Quaternion shipRotation; 

//        //Lists to store targets and bullets and stars
//        List<BoundingSphere> targetList = new List<BoundingSphere>();
//        List<Star> starList = new List<Star>();
//        List<Bullet> bulletList = new List<Bullet>();
//        List<Powerup> powerUps = new List<Powerup>();

//        //UFO
//        BoundingSphere UFOBound = new BoundingSphere();

//        //Powerups
//        //bool player.LavaCannon = false;
//        //bool player.Invuln = false;

//        //Sound
//        SoundEffect soundRegBullet;
//        SoundEffect soundLavaCannon;
//        SoundEffectInstance soundLavaCannonInstance;
//        SoundEffect soundExplosion;
//        SoundEffect soundShipExplosion;
//        SoundEffect soundPowerUp;
//        Song music;

//        float volume;
//        Vector3 bullDistVec;

//        //Reader and writer for the score
//        StreamWriter writer;
//        StreamReader reader;
//        const string path = @"Score.txt";

//        //Getters and setters
//        public static Random Random
//        {
//            get { return rnd; }
//        }

//        public SpriteBatch SpriteBatch
//        {
//            get { return spriteBatch; }
//        }
//        #endregion

//        #region HUD
//        //Big bold segoe
//        SpriteFont debugfont;
//        //Size 14 segoe
//        SpriteFont smallfont;
//        //size 35 italic
//        SpriteFont bigItalic;
//        //Aiming reticle
//        Texture2D reticle;

//        #region PauseMenu
//        //Pausescreen background
//        Texture2D pauseScreen;
//        //Sliderballs for volume sliders
//        Texture2D musicSliderBall;
//        Texture2D selectedSliderBall;
//        bool Paused = false;

//        //See what is selected in the pause menu
//        bool invertY = false;
//        bool musicVolumeSelected = false;
//        bool effectsVolumeSelected = false;

//        SliderBar musicVolumeSlider;
//        SliderBar effectsVolumeSlider;
//        #endregion


//        #endregion

//        #region Kinect

//        //Enable this to use kinect, otherwise keyboard is used to control
//        bool KINECT_ENABLE = false;
//        KinectSensor sensor;
//        Texture2D kinectRGB;
//        bool resetjoints;

//        #region Speech
//        KinectAudioSource audio;
//        SpeechRecognitionEngine sr;
        
//        Stream stream;
//        #endregion

//        #region Debug
//        bool debug = false;
//        bool debugcamera = false;

//        #endregion

//        #region Joints

//        Vector3 Head;
//        Vector3 LH;
//        Vector3 RH;

//        Vector3 LHHome;
//        Vector3 RHHome;

//        #endregion

//        #region Constants

//        float HandYAboveHome = 30f;
//        float TiltDifference = 30f;

//        #endregion

//        #endregion

//        #region Fire
//        // Here's the really fun part of the sample, the particle systems! These are
//        // drawable game components, so we can just add them to the components
//        // collection. Read more about each particle system in their respective source
//        // files.
//        //ExplosionParticleSystem explosion;
//        //ExplosionSmokeParticleSystem smoke;

//        // a timer that will tell us when it's time to trigger another explosion.
//        const float TimeBetweenExplosions = 2.0f;
//        float timeTillExplosion = 0.0f;

//        #endregion 



//        //CONSTRUCTOR
//        public Game1()
//        {
//            graphics = new GraphicsDeviceManager(this);
//            Content.RootDirectory = "Content";

//            // create the particle systems and add them to the components list.
//            // we should never see more than one explosion at once
//            //explosion = new ExplosionParticleSystem(this, 1);
//            //Components.Add(explosion);

//            // but the smoke from the explosion lingers a while.
//            //smoke = new ExplosionSmokeParticleSystem(this, 2);
//            //Components.Add(smoke);

//            // enable the tap gesture for changing particle effects
//            //TouchPanel.EnabledGestures = GestureType.Tap;
//        }


//        //METHODS
//        #region Initialization Methods

//        protected override void Initialize()
//        {
//            graphics.PreferredBackBufferWidth = windowWidth;
//            graphics.PreferredBackBufferHeight = windowHeight;
//            graphics.IsFullScreen = false;
//            graphics.ApplyChanges();
//            Window.Title = "Space Kinect";

//            #region Kinect
//            //Joint home positions will be reset when the user enters view of the camera
//            resetjoints = true;
//            DiscoverKinectSensor();
//            Head = new Vector3(0, 0, 0);
//            LH = new Vector3(0, 0, 0);
//            RH = new Vector3(0, 0, 0);
//            #endregion

//            InitializeSpeech();
//            base.Initialize();
//        }

//        protected override void LoadContent()
//        {
//            spriteBatch = new SpriteBatch(GraphicsDevice);

//            device = graphics.GraphicsDevice;

//            debugfont = Content.Load<SpriteFont>("debugfont");
//            smallfont = Content.Load<SpriteFont>("small");
//            bigItalic = Content.Load<SpriteFont>("bigItalic");

//            effect = Content.Load<Effect>("effects");
//            sceneryTexture = Content.Load<Texture2D>("highway2");
//            bulletTexture = Content.Load<Texture2D>("bullet");
//            starTexture = Content.Load<Texture2D>("star1");
//            reticle = Content.Load<Texture2D>("reticle2");
//                //userbar
//            barTexture = Content.Load<Texture2D>("DisplayBar");
//            bar_life = Content.Load<Texture2D>("Life");
//            bar_health_disabled = Content.Load<Texture2D>("health_disabled"); 
//            bar_health_enabled = Content.Load<Texture2D>("health_enabled"); 
//            bar_health_end = Content.Load<Texture2D>("health_end");
//            bar_music_muted = Content.Load<Texture2D>("music_muted");
//            bar_music_unmuted = Content.Load<Texture2D>("music_unmuted");

//            pauseScreen = Content.Load<Texture2D>("PauseScreen");
//            musicSliderBall = Content.Load<Texture2D>("sliderball");
//            selectedSliderBall = Content.Load<Texture2D>("sliderballselected");
            
//            targetModel = Content.Load<Model>("Asteroid");
//            UFOModel = Content.Load<Model>("UFO");

//            soundRegBullet = Content.Load<SoundEffect>("BulletSound2");
//            soundLavaCannon = Content.Load<SoundEffect>("BulletSound");
//            soundLavaCannonInstance = soundLavaCannon.CreateInstance();
//            soundShipExplosion = Content.Load<SoundEffect>("Explosion2");
//            soundExplosion = Content.Load<SoundEffect>("Explosion3");
//            soundPowerUp = Content.Load<SoundEffect>("PowerUp");
//            music = Content.Load<Song>("sadtouchMp3");
//            MediaPlayer.Play(music);
//            MediaPlayer.IsRepeating = true;
//            MediaPlayer.Volume = 0.5f;

//            musicVolumeSlider = new SliderBar(new Vector2(638, 330), new Vector2(971, 330), 5f);
//            effectsVolumeSlider = new SliderBar(new Vector2(638, 400), new Vector2(971, 400), 5f);

//            nextTunnel = -100;
//            SetUpBoundingBoxes();
//            AddTargets();
//            nextTunnel = 0;
//            SetUpShip();
//            SetUpVertices();
//            SetUpBoundingBoxes();
//            SetUpStars(nextTunnel);
//            AddTargets();
//            AddPowerups();
//        }

//        protected override void UnloadContent()
//        {
//            //Cleanup
//            if (KINECT_ENABLE)
//            {
//                stream.Close();
//                audio.Stop();
//            }
//            //sr.Dispose();
//        }
        
//        private void AddTargets()
//        {
//            float radius = 0;

//            for (int i=0; i<noOfTargets; i++)
//            {
//                int x = random.Next(100) + nextTunnel + 100;
//                int y = random.Next(mapHeight);
//                int z = -random.Next(mapWidth);
//                radius = random.Next(1, 5);
//                radius = 1 / radius;

//                BoundingSphere newTarget = new BoundingSphere(new Vector3(x, y, z), radius);

//                if (CheckTargetSetUpCollision(newTarget) == CollisionType.None)
//                    targetList.Add(newTarget);
//                else
//                    i--;
//            }
//        }

//        private void AddPowerups()
//        {
//            //Lava cannon
//            Powerup lavaCnn = new Powerup();
//            lavaCnn.enabled = Content.Load<Texture2D>("lava_enabled");
//            lavaCnn.disabled = Content.Load<Texture2D>("lava_disabled");
//            lavaCnn.Name = "Lava Cannon";
//            powerUps.Add(lavaCnn);

//            //Invincible
//            Powerup invincible = new Powerup();
//            invincible.enabled = Content.Load<Texture2D>("invincible_enabled");
//            invincible.disabled = Content.Load<Texture2D>("invincible_disabled");
//            invincible.Name = "Invincibility";
//            powerUps.Add(invincible);

//            //Invert Y
//            Powerup inverty = new Powerup();
//            inverty.enabled = Content.Load<Texture2D>("inverty_down");
//            inverty.disabled = Content.Load<Texture2D>("inverty_up");
//            inverty.Name = "InvertY";
//            powerUps.Add(inverty);
//        }

//        private void AddCluster(float bigRad, Vector3 bigVec)
//        {
//            float radius = 0;           

//            while (bigRad > .3)
//            {
//                radius = bigRad / (random.Next(5)+2);
//                float x = bigVec.X + (1/bigRad * random.Next(2));
//                float y = bigVec.Y + (1 / bigRad * random.Next(2));
//                float z = bigVec.Z + (1 / bigRad * random.Next(2));
                
//                BoundingSphere newTarget = new BoundingSphere(new Vector3(x, y, z), radius);

//                if (CheckTargetSetUpCollision(newTarget) == CollisionType.None)
//                {
//                    targetList.Add(newTarget);
//                    bigRad -= radius;
//                }
//            }
                
//        }

//        private void addUFO() 
//        {
//            if (UFOBound == null)
//            {
//                float radius;
//                int x = nextTunnel + 100;
//                int y = mapHeight / 2;
//                int z = -mapWidth / 2;
//                radius = 1/2;

//                UFOBound = new BoundingSphere(new Vector3(x, y, z), radius);
//            }
//        }

//        private void SetUpShip()
//        {
//            //Position and rotation of starting position
//            Vector3 shipPos = new Vector3(0, 2, -(float)mapWidth / 2);
//            Quaternion shipRot = Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), MathHelper.PiOver2);
//            Model shipModel = Content.Load<Model>("RocketPlain");

//            player = new Player(shipModel, shipPos, shipRot);
//        }

//        private void SetUpVertices()
//        {
//            //Used to create the textures
//            List<VertexPositionNormalTexture> allthethings = new List<VertexPositionNormalTexture>();
//            for (int x = nextTunnel; x < nextTunnel + 200; x += 5)
//            {
//                //Highway
//                allthethings.Add(new VertexPositionNormalTexture(new Vector3(x, 0, 0), new Vector3(0, 0, 0), new Vector2(0, 1)));
//                allthethings.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -mapWidth), new Vector3(0, 0, 0), new Vector2(0, 0)));
//                allthethings.Add(new VertexPositionNormalTexture(new Vector3(x + 5, 0, 0), new Vector3(0, 0, 0), new Vector2(1, 1)));

//                allthethings.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -mapWidth), new Vector3(0, 0, 0), new Vector2(0, 0)));
//                allthethings.Add(new VertexPositionNormalTexture(new Vector3(x + 5, 0, -mapWidth), new Vector3(0, 0, 0), new Vector2(1, 0)));
//                allthethings.Add(new VertexPositionNormalTexture(new Vector3(x + 5, 0, 0), new Vector3(0, 0, 0), new Vector2(1, 1)));
               
//            }
//            mapVertexBuffer = new VertexBuffer(device, VertexPositionNormalTexture.VertexDeclaration, allthethings.Count, BufferUsage.WriteOnly);
//            mapVertexBuffer.SetData<VertexPositionNormalTexture>(allthethings.ToArray());
//        }

//        private void SetUpStars(int length)
//        {
//            //Adds stars
//            for (int i = 0; i < numberOfStars; i++)
//            {
//                //Initialise + positions of stars
//                Star temp = new Star();
//                int x = rnd.Next(length + 200); 
//                int y = rnd.Next(starSpread * mapHeight) - ((starSpread/4) * mapHeight);
//                int z = -rnd.Next(starSpread * mapWidth) + ((starSpread/2) *(mapWidth-2));

//                //If it is within the bounds of the map, make it... not
//                int tempswitch = rnd.Next(2);
//                if (y < mapHeight + distanceAddition && y > 0 - distanceAddition && z > -mapWidth -distanceAddition && z < 0 + distanceAddition)
//                {
//                    //Width
//                    if (z > -mapWidth - distanceAddition && z < 0 + distanceAddition)
//                    {
//                        if (tempswitch == 1)
//                        {
//                            z += (mapWidth + distanceAddition);
//                        }
//                        else
//                        {
//                            z -= (mapWidth + distanceAddition);
//                        }
//                    }
//                    //Height
//                    if (y < mapHeight + distanceAddition && y > 0 - distanceAddition)
//                    {
//                        if (tempswitch == 1)
//                        {
//                            y += (mapHeight + distanceAddition);
//                        }
//                        else
//                        {
//                            y -= (mapHeight + distanceAddition);
//                        }
//                    }
//                }
                
//                //handles stars on the ground
//                if (y == 0)
//                {
//                    y -= 2;
//                }
//                temp.position = new Vector3(x,y,z);
//                starList.Add(temp);
//            }


//            //Removes old stars
//            for (int i = 0; i < starList.Count; i++ )
//            {
//                if (starList[i].position.X < player.Position.X - 200)
//                {
//                    starList.RemoveAt(i);
//                }
//            }

//        }

//        private void SetUpBoundingBoxes()
//        {
//            Vector3[] boundaryPoints = new Vector3[2];

//            boundaryPoints[0] = new Vector3(nextTunnel - 100, 0, 0);
//            boundaryPoints[1] = new Vector3(nextTunnel + 300, mapHeight, -mapWidth);
//            mapBox = BoundingBox.CreateFromPoints(boundaryPoints);
//        }

//        private void OnDeath(GameTime gameTime)
//        {
//            soundShipExplosion.Play(0.5f * effectsVolumeSlider.getValue() / 10, 0, 0);
            
//            //if player has lives left
//            if (player.Lives > 0)
//            {
//                player.Invuln = true;
//                player.InvulnStartTime = gameTime.TotalGameTime.TotalMilliseconds;
//                player.Health = 100;
//                player.Lives--;
//            }
//            //otherwise, game over (restarts atm but should be changed to lead to some end game sequence, saving score, going back to main menu, etc.
//            else
//            {
//                //RecordScore(totalScore);
//                ResetGame();
                
//                firingspeed = DefaultFiringSpeed;
//                player.LavaCannon = false;
//                player.Lives = 3;
//            }
//        }

//        protected void ResetGame()
//        {
//            DrawTunnel();
//            targetList.Clear();
//            bulletList.Clear();
//            nextTunnel = -100;
//            AddTargets();
//            nextTunnel = 0;
//            AddTargets();
//            SetUpShip();
//            gameSpeed = 2.0f;
//        }

//        #endregion

//        #region Update Methods

//        protected override void Update(GameTime gameTime)
//        {
//            #region KinectOutOfBounds
//            //If player is not in kinect camera range
//            if (CheckOutOfBounds())
//            {
//                if (resetjoints == false)
//                {
//                    resetjoints = true;
//                    base.Draw(gameTime);
//                }
//                else
//                {
//                }
//                return;
//            }
//            //If player has moved back in range
//            if (resetjoints == true)
//            {
//                RHHome = RH;
//                LHHome = LH;
//                resetjoints = false;
//            }
//            #endregion

//            //Move the ship forward
//            float moveSpeed = gameTime.ElapsedGameTime.Milliseconds / 500.0f * gameSpeed;
//            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
            
//            player.MoveForward(moveSpeed);

//            // if we should be demoing the explosions effect, check to see if it's
//            // time for a new explosion.
//            UpdateExplosions(dt);

//            ProcessKeyboard(gameTime);
//            UpdateCamera();
//            UpdateBulletPositions(moveSpeed);
//            UpdateTargets();
//            updateUFO();
            
//            //Check collisions of ship
//            //BoundingSphere shipSphere = new BoundingSphere(shipPosition, 0.04f);
//            player.UpdateBoundSphere();
//            CheckShipCollision(player.Bound);

//            if (player.Health <= 0)
//            {
//                player.Lives--;
//                OnDeath(gameTime);
//            }

//            //Updates relevant powerups
//            CheckPowerups(gameTime);

//            //Checks when to create the next tunnel
//            if ((int)player.Position.X > nextTunnel)
//                GenerateTunnel();

//            //Update score
//            totalScore = (int)(player.Position.X/2) + targetScore;

//            base.Update(gameTime);
//        }

//        // this function is called when we want to demo the explosion effect. it
//        // updates the timeTillExplosion timer, and starts another explosion effect
//        // when the timer reaches zero.
//        private void UpdateExplosions(float dt)
//        {
//            timeTillExplosion -= dt;
//            if (timeTillExplosion < 0)
//            {
//                Vector2 where = Vector2.Zero;
//                // create the explosion at some random point on the screen.
//                //where.X = RandomBetween(0, graphics.GraphicsDevice.Viewport.Width);
//                where.X = player.Position.X;
//                where.Y = player.Position.Y;
//                //where.Y = RandomBetween(0, graphics.GraphicsDevice.Viewport.Height);

//                // the overall explosion effect is actually comprised of two particle
//                // systems: the fiery bit, and the smoke behind it. add particles to
//                // both of those systems.
//                //explosion.AddParticles(where);
//                //smoke.AddParticles(where);

//                // reset the timer.
//                timeTillExplosion = TimeBetweenExplosions;
//            }
//        }

//        private void UpdateCamera()
//        {
//            Vector3 campos = new Vector3(0, 0.1f, 0.6f);
//            campos = Vector3.Transform(campos, Matrix.CreateFromQuaternion(player.Rotation));
//            campos += player.Position;

//            Vector3 camup = new Vector3(0, 1, 0);
//            camup = Vector3.Transform(camup, Matrix.CreateFromQuaternion(player.Rotation));

//            viewMatrix = Matrix.CreateLookAt(campos, player.Position, camup);
//            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 100.0f);

//            cameraPosition = campos;
//            cameraUpDirection = camup;

//        }

//        private void UpdateBulletPositions(float moveSpeed)
//        {
//            for (int i = 0; i < bulletList.Count; i++)
//            {
//                Bullet currentBullet = bulletList[i];
//                //moves bullet at 5 * ship speed
//                MoveForward(ref currentBullet.position, currentBullet.rotation, moveSpeed * 5.0f);
//                bulletList[i] = currentBullet;

//                BoundingSphere bulletSphere = new BoundingSphere(currentBullet.position, 0.05f);
//                CollisionType colType = CheckCollision(bulletSphere);
//                if (colType != CollisionType.None)
//                {
//                    bulletList.RemoveAt(i);
//                    i--;
//                }
//                else if (currentBullet.position.X - player.Position.X > 75)
//                {
//                    bulletList.RemoveAt(i);
//                    i--;
//                }
//            }
//        }

//        private void UpdateTargets()
//        {
//            for (int i = 0; i < targetList.Count; i++)
//            {
//                //remove target if ship passes it
//                if (targetList[i].Center.X - player.Position.X < 0)
//                {
//                    targetList.RemoveAt(i);
//                    i--;
//                }
//                //update anaimation/movement?
//            }
//        }

//        private void MoveForward(ref Vector3 position, Quaternion rotationQuat, float speed)
//        {
//            Vector3 addVector = Vector3.Transform(new Vector3(0, 0, -1), rotationQuat);
//            position += addVector * speed;
//        }

//        private void GenerateTunnel()
//        {
//            SetUpVertices();
//            SetUpBoundingBoxes();
//            nextTunnel += 100;
//            AddTargets();
//            SetUpStars(nextTunnel);
//            addUFO();
//            //Gameplay elements that increase
//            gameSpeed += 0.5f;
//            noOfTargets++;
//        }

//        private void ProcessKeyboard(GameTime gameTime)
//        {
//            float leftRightRot = 0;
//            float upDownRot = 0;
//            //Speeds for turning/going up and down
//            //Up/Down speed is considerably slower for ease of controlling with kinect
//            float turningSpeed = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
//            float updownSpeed = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
//            if (KINECT_ENABLE == true)
//                updownSpeed /= 4;

//            turningSpeed *= 1f;

//            KeyboardState keys = Keyboard.GetState();

//            //Handles whether or not we are in debugmode
//            if (keys.IsKeyDown(Keys.OemTilde))
//            {
//                if (!oldstate.IsKeyDown(Keys.OemTilde))
//                {
//                    if (debugmode == false)
//                        debugmode = true;
//                    else
//                        debugmode = false;
//                }
//            }

//            //Mute audio
//            if (keys.IsKeyDown(Keys.M))
//            {
//                if (!oldstate.IsKeyDown(Keys.M))
//                {
//                    if (MediaPlayer.IsMuted == false)
//                        MediaPlayer.IsMuted = true;
//                    else
//                        MediaPlayer.IsMuted = false;
//                }
//            }
//            oldstate = keys;

//            //If user is controlling game with KINECT camera
//            if (KINECT_ENABLE == true)
//            {
//                if (invertY == false)
//                {

//                    //Up
//                    if ((RH.Y + LH.Y) / 2 + HandYAboveHome < RHHome.Y)
//                    {
//                        upDownRot += updownSpeed;
//                    }
//                    //Down
//                    else if ((RH.Y + LH.Y) / 2 - HandYAboveHome > RHHome.Y)
//                    {
//                        upDownRot -= updownSpeed;
//                    }
//                }
//                else
//                {
//                    //Up
//                    if ((RH.Y + LH.Y) / 2 + HandYAboveHome < RHHome.Y)
//                    {
//                        upDownRot -= updownSpeed;
//                    }
//                    //Down
//                    else if ((RH.Y + LH.Y) / 2 - HandYAboveHome > RHHome.Y)
//                    {
//                        upDownRot += updownSpeed;
//                    }
//                }
//                //Turn Left
//                if (LH.Y - RH.Y > TiltDifference)
//                {
//                    leftRightRot -= turningSpeed;
//                }
//                //Turn right
//                else if (RH.Y - LH.Y > TiltDifference)
//                {
//                    leftRightRot += turningSpeed;
//                }

//                //fire bullets
//                FireBullets(gameTime);

//            }
//            //If keyboard is being used
//            else
//            {
//                if (keys.IsKeyDown(Keys.Down))
//                    upDownRot -= turningSpeed;
//                if (keys.IsKeyDown(Keys.Up))
//                    upDownRot += turningSpeed;
//                if (keys.IsKeyDown(Keys.Right))
//                    leftRightRot += turningSpeed;
//                if (keys.IsKeyDown(Keys.Left))
//                    leftRightRot -= turningSpeed;
//                if (keys.IsKeyDown(Keys.Space))
//                {
//                    FireBullets(gameTime);
//                }
//            }

//            Quaternion additionalRot = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), leftRightRot) * Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRot);
//            player.Rotation *= additionalRot;

//            //strafing
//            if (keys.IsKeyDown(Keys.W))
//                player.Position -= new Vector3(0, -.015f, 0);
//            if (keys.IsKeyDown(Keys.S))
//                player.Position -= new Vector3(0, .015f, 0);
//            if (keys.IsKeyDown(Keys.D))
//                player.Position -= new Vector3(0, 0, -.015f);
//            if (keys.IsKeyDown(Keys.A))
//                player.Position -= new Vector3(0, 0, .015f);
            
//            //Increase/decrease game speed
//            if (keys.IsKeyDown(Keys.D1))
//                gameSpeed *= 1.01f;
//            if (keys.IsKeyDown(Keys.D2))
//                gameSpeed /= 1.01f;

//            //Recording score and Exit
//            if (keys.IsKeyDown(Keys.Escape))
//            {
//                RecordScore(targetScore);
//                Exit();
//            }
//        }

//        private void FireBullets(GameTime gameTime)
//        {
//            double currentTime = gameTime.TotalGameTime.TotalMilliseconds;

//            if (currentTime - player.LastBulletTime > firingspeed)
//            {
//                Bullet newBullet = new Bullet();
//                newBullet.position = player.Position;
//                newBullet.rotation = player.Rotation;
//                bulletList.Add(newBullet);

//                BulletSounds();

//                player.LastBulletTime = currentTime;
//            }
//        }

//        private void BulletSounds()
//        {
//            if (player.LavaCannon == true)
//            {
//                if (soundLavaCannonInstance.State == SoundState.Stopped)
//                    soundLavaCannonInstance.Play();
//            }
//            else
//                soundRegBullet.Play(effectsVolumeSlider.getValue()/10, 0f, 0f);
//        }

//        private void CheckPowerups(GameTime gameTime)
//        {
//            //If 5 targets have been destroyed
//            if (DestroyedTargets == 5)
//            {
//                player.LavaCannon = true;
//                soundPowerUp.Play();
//                firingspeed = 1;
//                DestroyedTargets = 0;
//                player.LavaCannonStartTime = gameTime.TotalGameTime.TotalMilliseconds;
//            }
//            //If powerup has expired
//            if (firingspeed == 1 && gameTime.TotalGameTime.TotalMilliseconds - player.LavaCannonStartTime > 10000)
//            {
//                player.LavaCannon = false;
//                firingspeed = DefaultFiringSpeed;
//            }

//            if (player.Invuln == true)
//            {
//                if (gameTime.TotalGameTime.TotalMilliseconds - player.InvulnStartTime > 5000)
//                    player.Invuln = false;
//            }
//        }

//        private CollisionType CheckCollision(BoundingSphere sphere)
//        {
//            //this method is now only used by bullets, and determines whether a bullet has collided with a boundary wall or a target
//            if (mapBox.Contains(sphere) != ContainmentType.Contains)
//                return CollisionType.Boundary;

//            for (int i = 0; i < targetList.Count; i++)
//            {
//                if (targetList[i].Contains(sphere) != ContainmentType.Disjoint)
//                {
//                    //make cluster on destroyed big one
//                    //if (targetList[i].Radius > .3)
//                    {
//                        float radius = targetList[i].Radius;
//                        Vector3 center = targetList[i].Center;
//                        targetList.RemoveAt(i);
//                        AddCluster(radius, center);
//                    }
//                    //else
//                      //  targetList.RemoveAt(i);
                    
//                    i--;
//                    targetScore+=10;

//                    if (player.LavaCannon == false)
//                        DestroyedTargets++;

//                    bullDistVec = (sphere.Center - player.Position);
//                    PlayExplosion(bullDistVec.X);

//                    return CollisionType.Target;
//                }
//            }
//            return CollisionType.None;
//        }

//        private CollisionType CheckShipCollision(BoundingSphere sphere)
//        {
//            //determines what the ship collided with

//            //if sides of tunnel:
//            if (mapBox.Contains(sphere) != ContainmentType.Contains)
//            {
//                //set the rotation flat, and facing forwards
//                player.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), MathHelper.PiOver2);

//                //floor
//                if (player.Position.Y < 1)
//                    player.Position += new Vector3(0, 0.5f, 0);
//                //roof
//                if (player.Position.Y > mapHeight - 1)
//                    player.Position += new Vector3(0, -0.5f, 0);
//                //left wall
//                if (player.Position.Z < mapWidth + 1)
//                    player.Position += new Vector3(0, 0, 0.5f);
//                ///right wall
//                if (player.Position.Z > -1)
//                    player.Position += new Vector3(0, 0, -1.0f);

//                if (player.Invuln == false)
//                    player.Health -= 10;

//                return CollisionType.Boundary;
//            }
            
//            for (int i = 0; i < targetList.Count; i++)
//            {
//                //if collision with asteroid:
//                if (targetList[i].Contains(sphere) != ContainmentType.Disjoint)
//                {
                    
//                    targetList.RemoveAt(i);
//                    i--;
                    
//                    bullDistVec = (sphere.Center - player.Position);
//                    PlayExplosion(bullDistVec.X);

//                    if (player.Invuln == false)
//                        player.Health -= 30;

//                    return CollisionType.Target;
//                }
//            }
//            return CollisionType.None;
//        }

//        private CollisionType CheckTargetSetUpCollision(BoundingSphere sphere)
//        {
//            //check that a generated target doesn't collide with the tunnel sides
//            if (mapBox.Contains(sphere) != ContainmentType.Contains)
//                return CollisionType.Boundary;

//            //check that a generated target doesn't collide with a previously generated target
//            for (int i = 0; i < targetList.Count; i++)
//            {
//                if (targetList[i].Contains(sphere) != ContainmentType.Disjoint)
//                    return CollisionType.Target;
//            }
//            return CollisionType.None;
//        }

//        private void PlayExplosion(float Distance)
//        {
//            if (Distance >= 90)
//            {
//                volume = 0.1f;
//                soundExplosion.Play(volume * effectsVolumeSlider.getValue()/10, 0, 0);
//            }
//            else
//            {
//                volume = (100-Distance)/100f;
//                soundExplosion.Play(volume * effectsVolumeSlider.getValue()/10, 0, 0);
//            }
//        }

//        private void updateUFO() 
//        {
//            if (UFOBound != null)
//            {
//                if (player.Position.Y - UFOBound.Center.Y > 5)
//                    UFOBound.Center.Y ++;
//                if (player.Position.Y - UFOBound.Center.Y > -5)
//                    UFOBound.Center.Y--;
//                if (player.Position.Z - UFOBound.Center.Z > 5)
//                    UFOBound.Center.Z++;
//                if (player.Position.Z - UFOBound.Center.Z > 5)
//                    UFOBound.Center.Z--;
//                if (player.Position.X - UFOBound.Center.X < 5)
//                    UFOBound.Center.X = player.Position.X + 5;

//                //debug stuff
//                UFOBound.Center.X = player.Position.X + 5;
//                UFOBound.Center.Z = player.Position.Z;
//                UFOBound.Center.Y = player.Position.Y;
//                DrawUFO();
//            }
//        }

//        #endregion

//        #region Draw Methods

//        protected override void Draw(GameTime gameTime)
//        {
//            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Transparent, 1.0f, 0);
//            //If player is not in kinect camera range
//            if (CheckOutOfBounds())
//            {
//                Paused = true;
//                DrawPauseMenu(gameTime);
//                return;
//            }
//            else
//            {
//                Paused = false;
//            }

//            DrawTunnel();
//            DrawKinectDebug(true);
//            player.Draw(projectionMatrix, viewMatrix);
//            DrawTargets();
//            DrawStars();
//            DrawBullets();
//            DrawHUD(gameTime);

//            base.Draw(gameTime);
//        }

//        #region Drawing Objects
       
//        private void DrawSpaceShip()
//        {

//        }

//        private void DrawTunnel()
//        {
//            //Floor
            
//            effect.CurrentTechnique = effect.Techniques["Textured"];
//            effect.Parameters["xWorld"].SetValue(Matrix.Identity);
//            effect.Parameters["xView"].SetValue(viewMatrix);
//            effect.Parameters["xProjection"].SetValue(projectionMatrix);
//            effect.Parameters["xTexture"].SetValue(sceneryTexture);

//            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
//            {
//                int i = 0;
//                pass.Apply();
//                device.SetVertexBuffer(mapVertexBuffer);
//                device.SamplerStates[i] = SamplerState.LinearClamp;
//                device.DrawPrimitives(PrimitiveType.TriangleList, 0, mapVertexBuffer.VertexCount / 3);
//                i++;
//            }
//        }

//        private void DrawBullets()
//        {
//            device.BlendState = BlendState.Additive;
//            if (bulletList.Count > 0)
//            {
//                VertexPositionTexture[] bulletVertices = new VertexPositionTexture[bulletList.Count * 6];
//                int i = 0;
//                foreach (Bullet currentBullet in bulletList)
//                {
//                    Vector3 center = currentBullet.position;

//                    bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 1));
//                    bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 0));
//                    bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 0));

//                    bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 1));
//                    bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 1));
//                    bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 0));
//                }

//                effect.CurrentTechnique = effect.Techniques["PointSprites"];
//                effect.Parameters["xWorld"].SetValue(Matrix.Identity);
//                effect.Parameters["xProjection"].SetValue(projectionMatrix);
//                effect.Parameters["xView"].SetValue(viewMatrix);
//                effect.Parameters["xCamPos"].SetValue(cameraPosition);
//                effect.Parameters["xTexture"].SetValue(bulletTexture);
//                effect.Parameters["xCamUp"].SetValue(cameraUpDirection);
//                effect.Parameters["xPointSpriteSize"].SetValue(0.1f);

//                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
//                {
//                    pass.Apply();
//                    device.DrawUserPrimitives(PrimitiveType.TriangleList, bulletVertices, 0, bulletList.Count * 2);
//                }
//            }
//            device.BlendState = BlendState.Opaque;
//        }

//        private void DrawStars() 
//        {
//            device.BlendState = BlendState.Additive;
//            if (starList.Count > 0)
//            {
//                VertexPositionTexture[] starVertices = new VertexPositionTexture[starList.Count * 6];
//                int i = 0;
//                foreach (Star currentStar in starList)
//                {
//                    Vector3 center = currentStar.position;

//                    starVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 1));
//                    starVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 0));
//                    starVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 0));

//                    starVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 1));
//                    starVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 1));
//                    starVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 0));
//                }

//                effect.CurrentTechnique = effect.Techniques["PointSprites"];
//                effect.Parameters["xWorld"].SetValue(Matrix.Identity);
//                effect.Parameters["xProjection"].SetValue(projectionMatrix);
//                effect.Parameters["xView"].SetValue(viewMatrix);
//                effect.Parameters["xCamPos"].SetValue(cameraPosition);
//                effect.Parameters["xTexture"].SetValue(starTexture);
//                effect.Parameters["xCamUp"].SetValue(cameraUpDirection);
//                effect.Parameters["xPointSpriteSize"].SetValue(0.1f);

//                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
//                {
//                    int m = 0;
//                    pass.Apply();
//                    device.SamplerStates[m] = SamplerState.LinearClamp;
//                    device.DrawUserPrimitives(PrimitiveType.TriangleList, starVertices, 0, starList.Count * 2);
//                    m++;
//                }
//            }
//            device.BlendState = BlendState.Opaque;
//        }

//        private void DrawTargets()
//        {
//            for (int i = 0; i < targetList.Count; i++)
//            {
//                foreach (ModelMesh mesh in targetModel.Meshes)
//                {
//                    foreach (BasicEffect effect in mesh.Effects)
//                    {
//                        effect.EnableDefaultLighting();
//                        effect.PreferPerPixelLighting = true;

//                        effect.World = Matrix.CreateTranslation(targetList[i].Center);
//                        effect.World = Matrix.CreateScale(targetList[i].Radius) * Matrix.CreateTranslation(targetList[i].Center);
//                        effect.Projection = projectionMatrix;
//                        effect.View = viewMatrix;
//                    }
//                    mesh.Draw();
//                }
//            }
//        }
//        private void DrawUFO()
//        {
          
//                foreach (ModelMesh mesh in UFOModel.Meshes)
//                {
//                    foreach (BasicEffect effect in mesh.Effects)
//                    {
//                        effect.EnableDefaultLighting();
//                        effect.PreferPerPixelLighting = true;

//                        effect.World = Matrix.CreateTranslation(UFOBound.Center);
//                        effect.World = Matrix.CreateScale(UFOBound.Radius) * Matrix.CreateTranslation(UFOBound.Center);
//                        effect.Projection = projectionMatrix;
//                        effect.View = viewMatrix;
//                    }
//                    mesh.Draw();
//            }
//        }

//        #endregion

//        #region Drawing HUD


//        private void DrawHUD(GameTime gameTime)
//        {
//            //If you want this to appear when in debugmode, put it here 
//            if (debugmode == true)
//            {
//                spriteBatch.Begin();
//                spriteBatch.DrawString(smallfont, bulletList.Count.ToString(), new Vector2(50, 700), Color.White);
//                spriteBatch.DrawString(smallfont, targetList.Count.ToString(), new Vector2(50, 725), Color.CornflowerBlue);

//                spriteBatch.DrawString(smallfont, player.Position.X.ToString(), new Vector2(1200, 50), Color.White);
//                spriteBatch.DrawString(smallfont, player.Position.Y.ToString(), new Vector2(1200, 75), Color.White);
//                spriteBatch.DrawString(smallfont, player.Position.Z.ToString(), new Vector2(1200, 100), Color.White);

//                spriteBatch.DrawString(smallfont, UFOBound.Center.X.ToString(), new Vector2(1200, 225), Color.Red);
//                spriteBatch.DrawString(smallfont, UFOBound.Center.Y.ToString(), new Vector2(1200, 250), Color.Red);
//                spriteBatch.DrawString(smallfont, UFOBound.Center.Z.ToString(), new Vector2(1200, 275), Color.Red);

//                //spriteBatch.DrawString(smallfont, "Score " +score.ToString(), new Vector2(1200, 450), Color.White);
//                spriteBatch.DrawString(smallfont, "Highest Score " + GetHighScore(), new Vector2(1200, 470), Color.White);
//                //To display vector coordinates of other objects (if needed for testing)
                
//                spriteBatch.DrawString(smallfont, bullDistVec.X.ToString(), new Vector2(1200, 200), Color.White);

//                spriteBatch.DrawString(smallfont, "Speed " + gameSpeed.ToString(), new Vector2(1200, 500), Color.White);
//                spriteBatch.DrawString(smallfont, nextTunnel.ToString(), new Vector2(1200, 550), Color.White);
//                //To display the viewmatrix in full to the screen
//                /*
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M11).ToString(), new Vector2(1100, 200), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M12).ToString(), new Vector2(1150, 200), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M13).ToString(), new Vector2(1200, 200), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M14).ToString(), new Vector2(1250, 200), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M21).ToString(), new Vector2(1100, 225), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M22).ToString(), new Vector2(1150, 225), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M23).ToString(), new Vector2(1200, 225), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M24).ToString(), new Vector2(1250, 225), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M31).ToString(), new Vector2(1100, 250), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M32).ToString(), new Vector2(1150, 250), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M33).ToString(), new Vector2(1200, 250), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M34).ToString(), new Vector2(1250, 250), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M41).ToString(), new Vector2(1100, 275), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M42).ToString(), new Vector2(1150, 275), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M43).ToString(), new Vector2(1200, 275), Color.White);
//                spriteBatch.DrawString(smallfont, ((int)viewMatrix.M44).ToString(), new Vector2(1250, 275), Color.White);
//                */
//                spriteBatch.End();
//                device.DepthStencilState = DepthStencilState.Default;
//            }

//            ///If you want it to appear in general, put it here
//            DrawReticle();

//            //When game is running
//            if (Paused == false)
//            {
//                //Draws the bar along the top
//                spriteBatch.Begin();
//                spriteBatch.Draw(barTexture, new Vector2(0, 0), Color.White);
                
//                //For the lives
//                spriteBatch.DrawString(smallfont, "Lives", new Vector2(windowWidth - 150, 2), Color.White);
//                for (int i = 0; i < player.Lives; i++)
//                {
//                    spriteBatch.Draw(bar_life, new Vector2(windowWidth - ((i+2)*20), 0), Color.White);
//                }
                
//                //Health Bar Start
//                spriteBatch.Draw(bar_health_end, new Vector2(windowWidth - 401, 0), Color.White);
//                spriteBatch.DrawString(smallfont, "Health", new Vector2(windowWidth - 480, 2), Color.White);
//                //Health Bar Main
//                for (int i = 0; i < player.Health; i++)
//                {
//                    spriteBatch.Draw(bar_health_enabled, new Vector2(windowWidth - (400 - 2 * i), 0), Color.White);
//                    spriteBatch.Draw(bar_health_enabled, new Vector2(windowWidth - (400 - 2 * i - 1), 0), Color.White);
//                }
//                for (int i = 0; i < 100 - player.Health; i++)
//                {
//                    spriteBatch.Draw(bar_health_disabled, new Vector2(windowWidth - 200 - 2 * i, 0), Color.White);
//                    spriteBatch.Draw(bar_health_disabled, new Vector2(windowWidth - 200 - 2 * i - 1, 0), Color.White);
//                }
//                //Health Bar End
//                spriteBatch.Draw(bar_health_end, new Vector2(windowWidth - 200, 0), Color.White);
//                Color draw = new Color();
//                if(player.Health < 50){draw = Color.White;}else{draw = Color.Black;}
//                spriteBatch.DrawString(smallfont, player.Health.ToString() + "%", new Vector2(windowWidth - 315 - ((player.Health.ToString().ToCharArray().Count() - 3) * 10), 2), draw);

//                //Lava Cannon
//                if (player.LavaCannon != true)
//                {
//                    spriteBatch.Draw(powerUps[0].disabled, new Vector2(windowWidth - 600, 0), Color.White);
//                }
//                else
//                {
//                    spriteBatch.Draw(powerUps[0].enabled, new Vector2(windowWidth - 600, 0), Color.White);
//                    //Draw the number of seconds remaining
//                    spriteBatch.DrawString(smallfont, ((10000 - (gameTime.TotalGameTime.TotalMilliseconds - player.LavaCannonStartTime)) / 1000).ToString("0"), new Vector2(windowWidth - 580, 2), Color.White);
//                }

//                //Invincibility
//                if (player.Invuln != true)
//                {
//                    spriteBatch.Draw(powerUps[1].disabled, new Vector2(windowWidth - 600 - 60, 0), Color.White);
//                }
//                else
//                {
//                    spriteBatch.Draw(powerUps[1].enabled, new Vector2(windowWidth - 600 - 60, 0), Color.White);
//                    //Draw the number of seconds remaining
//                    spriteBatch.DrawString(smallfont, ((5000 - (gameTime.TotalGameTime.TotalMilliseconds - player.InvulnStartTime)) / 1000).ToString("0"), new Vector2(windowWidth - 580 - 60, 2), Color.White);
//                }

//                //Invert Y
//                if (invertY)
//                {
//                    spriteBatch.Draw(powerUps[2].enabled, new Vector2(windowWidth - 600 - 60 - 60 , 0), Color.White);
//                }
//                else
//                {
//                    spriteBatch.Draw(powerUps[2].disabled, new Vector2(windowWidth - 600 - 60 - 60, 0), Color.White);
//                }

//                //Music Muted/not muted
//                if (MediaPlayer.IsMuted)
//                {
//                    spriteBatch.Draw(bar_music_muted, new Vector2(160, 0), Color.White);
//                }
//                else
//                {
//                    spriteBatch.Draw(bar_music_unmuted, new Vector2(160, 0), Color.White);
//                }

//                //Score
//                spriteBatch.DrawString(smallfont, "Score: " + totalScore.ToString(), new Vector2(200, 2), Color.Red);

                

//                //SPACE KINECT!!!!!!!!!!!!!!!!!!!!!!!!!!
//                spriteBatch.DrawString(smallfont, "Space Kinect", new Vector2(20, 2), Color.White);
//                spriteBatch.End();
//                device.DepthStencilState = DepthStencilState.Default;
                

//            }
//        }

//        private void DrawReticle()
//        {
//            //Draws a reticle in the center of the screen (values obtained using trial and error lol)
//            spriteBatch.Begin();
//            spriteBatch.Draw(reticle, new Vector2(graphics.PreferredBackBufferWidth / 2 - 15, graphics.PreferredBackBufferHeight / 2 - 157), Color.White);
//            spriteBatch.End();
//            //Required to make things draw in correct order
//            device.DepthStencilState = DepthStencilState.Default;
//        }

//        private void PowerUpCues(GameTime gameTime)
//        {
//            //If firing speed powerup is enabled draw remaining time
//            if (player.LavaCannon == true)
//            {
//                spriteBatch.Begin();
//                spriteBatch.DrawString(smallfont, "Powerup time remaining: " + ((10000 - (gameTime.TotalGameTime.TotalMilliseconds - player.LavaCannonStartTime)) / 1000).ToString("0"), new Vector2(50, 100), Color.White);
//                spriteBatch.End();
//                device.DepthStencilState = DepthStencilState.Default;
//            }

//            if (player.Invuln == true)
//            {
//                spriteBatch.Begin();
//                spriteBatch.DrawString(smallfont, "Invulnarability left: " + ((5000 - (gameTime.TotalGameTime.TotalMilliseconds - player.InvulnStartTime)) / 1000).ToString("0"), new Vector2(50, 125), Color.White);
//                spriteBatch.End();
//                device.DepthStencilState = DepthStencilState.Default;
//            }
//        }

//        private void DrawGameElements()
//        {
//            spriteBatch.Begin();
//            spriteBatch.DrawString(smallfont, "Score: " + totalScore, new Vector2(50, 25), Color.White);
//            spriteBatch.DrawString(smallfont, "Lives: " + player.Lives, new Vector2(50, 50), Color.White);
//            spriteBatch.DrawString(smallfont, "Health: " + player.Health, new Vector2(50, 75), Color.White);
//            spriteBatch.End();
//            device.DepthStencilState = DepthStencilState.Default;

//        }
//        #endregion

//        #endregion

//        #region Pause Menu

//        private void DrawPauseMenu(GameTime gameTime)
//        {
//            spriteBatch.Begin();
//            //Draw Background
//            spriteBatch.Draw(pauseScreen, Vector2.Zero, Color.White);
//            //Draw head z position
//            spriteBatch.DrawString(debugfont, Head.Z.ToString(), new Vector2((float)(graphics.PreferredBackBufferWidth * .4), (float)(graphics.PreferredBackBufferHeight * .9)), Color.Black);
//            //Draw invert y true/false
//            spriteBatch.DrawString(debugfont, invertY.ToString(), new Vector2((float)(graphics.PreferredBackBufferWidth * .47), (float)(graphics.PreferredBackBufferHeight * .28)), Color.Black);

//            #region Sliders
//            //If music volume is being adjusted
//            if (musicVolumeSelected == true)
//            {
//                //Update sliderball position
//                updateSlider(musicVolumeSlider);
//                //Draw sliderballs
//                spriteBatch.Draw(selectedSliderBall, new Vector2(musicVolumeSlider.getSlider().X - 14, musicVolumeSlider.getSlider().Y - 14), Color.White);
//                spriteBatch.Draw(musicSliderBall, new Vector2(effectsVolumeSlider.getSlider().X - 14, effectsVolumeSlider.getSlider().Y - 14), Color.White);
//                MediaPlayer.Volume = musicVolumeSlider.getValue()/10;
//            }
//            //If effects volume is being adjusted
//            else if (effectsVolumeSelected == true)
//            {
//                updateSlider(effectsVolumeSlider);
//                spriteBatch.Draw(selectedSliderBall, new Vector2(effectsVolumeSlider.getSlider().X - 14, effectsVolumeSlider.getSlider().Y - 14), Color.White);
//                spriteBatch.Draw(musicSliderBall, new Vector2(musicVolumeSlider.getSlider().X - 14, musicVolumeSlider.getSlider().Y - 14), Color.White);
//            }

//            //If no volume is being adjusted
//            else
//            {
//                //Draw purple balls
//                spriteBatch.Draw(musicSliderBall, new Vector2(musicVolumeSlider.getSlider().X - 14, musicVolumeSlider.getSlider().Y - 14), Color.White);
//                spriteBatch.Draw(musicSliderBall, new Vector2(effectsVolumeSlider.getSlider().X - 14, effectsVolumeSlider.getSlider().Y - 14), Color.White);
//            }
//            #endregion

//            //Draw volume values
//            string musicValue = (musicVolumeSlider.getValue() * 10).ToString("N0");
//            string effectsValue = (effectsVolumeSlider.getValue() * 10).ToString("N0");
//            if (musicValue == "-1")
//                musicValue = "0";
//            if (effectsValue == "-1")
//                effectsValue = "0";

//            spriteBatch.DrawString(debugfont, musicValue, new Vector2(995, 292), Color.Black);
//            spriteBatch.DrawString(debugfont, effectsValue, new Vector2(995, 360), Color.Black);
//            spriteBatch.End();
//            base.Draw(gameTime);
//            return;

//        }

//        private void updateSlider(SliderBar slider)
//        {
//            //RHHOME is the value where the right hand was when slider had started adjusting

            
//            //If within the range to drag slider
//            if (RH.X < (RHHome.X + 100) && RH.X > RHHome.X-1)
//            {
//                float difference = RH.X- RHHome.X;
//                if (difference == -1)
//                    difference = 0;

//                if(musicVolumeSelected)
//                {
//                    musicVolumeSlider.setValue(difference / 10);
//                }
//                else if (effectsVolumeSelected)
//                {
//                    effectsVolumeSlider.setValue(difference / 10);
//                }
//            }

//        }
//        #endregion

//        #region Kinect/Sound Methods

//        private bool CheckOutOfBounds()
//        {
//            //Returns false if player's head is out of bounds
//            if ((Head.Z == 0 || Head.Z < 1.8 || Head.Z > 2.3) && KINECT_ENABLE == true || musicVolumeSelected==true || effectsVolumeSelected==true)
//            {
//                return true;
//            }
//            return false;
//        }

//        private void DrawKinectDebug(bool handdata)
//        {
//            if (debug == true)
//            {

//                spriteBatch.Begin();

//                if (debugcamera == true)
//                {
//                    //Draws kinect camera stream
//                    spriteBatch.Draw(kinectRGB, new Vector2(0, 0), null, Color.White, 0, Vector2.Zero, .60f, SpriteEffects.None, 0);

//                }
//                if (handdata == true)
//                {
//                    //Draws current positions of limbs
//                    spriteBatch.DrawString(debugfont, "LeftHand X: " + LH.X, new Vector2(0, graphics.PreferredBackBufferHeight - 100), Color.Red);
//                    spriteBatch.DrawString(debugfont, "LeftHand Y: " + LH.Y, new Vector2(0, graphics.PreferredBackBufferHeight - 70), Color.Red);
//                    spriteBatch.DrawString(debugfont, "LeftHand HOMEXY: " + LHHome.X + " " + LHHome.Y, new Vector2(0, graphics.PreferredBackBufferHeight - 40), Color.Red);

//                    spriteBatch.DrawString(debugfont, "RightHand X: " + RH.X, new Vector2(0, graphics.PreferredBackBufferHeight - 200), Color.Red);
//                    spriteBatch.DrawString(debugfont, "RightHand Y: " + RH.Y, new Vector2(0, graphics.PreferredBackBufferHeight - 170), Color.Red);
//                    spriteBatch.DrawString(debugfont, "RightHand Z: " + RH.Z, new Vector2(0, graphics.PreferredBackBufferHeight - 140), Color.Red);
//                    spriteBatch.DrawString(debugfont, "RightHand HOMEXY: " + RHHome.X + " " + RHHome.Y, new Vector2(0, graphics.PreferredBackBufferHeight - 40), Color.Red);
//                }

//                spriteBatch.End();
//                device.DepthStencilState = DepthStencilState.Default;
//            }
//        }

//        private void DiscoverKinectSensor()
//        {
//            foreach (KinectSensor s in KinectSensor.KinectSensors)
//            {
//                if (s.Status == KinectStatus.Connected)
//                {
//                    sensor = s;
//                    InitializeKinect();
//                    return;
//                }

//            }
//        }

//        private void InitializeKinect()
//        {
//            sensor.ColorStream.Enable(ColorImageFormat.YuvResolution640x480Fps15);
//            sensor.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(sensor_ColorFrameReady);

//            sensor.SkeletonStream.Enable(new TransformSmoothParameters()
//            {
//                Smoothing = 0.5f,
//                Correction = 0.5f,
//                Prediction = 0.5f,
//                JitterRadius = 0.1f,
//                MaxDeviationRadius = 0.04f
//            });
//            sensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(sensor_SkeletonFrameReady);
//            try
//            {
//                sensor.Start();
//            }
//            catch
//            {
//                sensor.Stop();
//            }

//        }

//        private void InitializeSpeech()
//        {
//            //requires kinect connected else ri == null
//            RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == "SR_MS_en-US_Kinect_10.0").FirstOrDefault();
//            if (ri == null)
//            {
//                    throw new ApplicationException("Could not locate speech recognizer. Ensure you have the Kinect Speech SDK/runtime/MSKinectLangPack_enUS installed.");
//            }

//            //Phrases that will be recognised added
//            Choices phrases = new Choices();
//            phrases.Add(
//                "faster", 
//                "slower", 
//                "stop", 
//                "invert y",
//                "music volume",
//                "effects volume",
//                "okay");
//            GrammarBuilder gb = new GrammarBuilder();
//            //adding our phrases to the grammar builder
//            gb.Append(phrases);
//            //gb.Culture = ri.Culture;

//            sr = new SpeechRecognitionEngine(ri.Id);

//            if (KINECT_ENABLE)
//            {
//                audio = sensor.AudioSource; //using kinect as source not pc mic
//                audio.AutomaticGainControlEnabled = false; // Per sample documentation, "Important to turn this off for speech recognition"
//                audio.EchoCancellationMode = EchoCancellationMode.None; //as above
//                stream = audio.Start();
//                sr.SetInputToAudioStream(stream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
//            }
//            else
//            {
//                sr.SetInputToDefaultAudioDevice();
//            }

//            sr.LoadGrammar(new Grammar(gb));
          
//            sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);
//            sr.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(sr_SpeechHypothesized);
//            sr.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sr_SpeechRecognitionRejected);
//            //set the recognition engine to keep running after recognizing a command.
//            //if we had used RecognizeMode.Single, the engine would quite listening after
//            //the first recognized command.
//            sr.RecognizeAsync(RecognizeMode.Multiple);
//        }
        
//        void sr_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
//        {
            
//        }

//        void sr_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
//        {
            
//        }

//        void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
//        {
//            if (e.Result.Text.ToLower() == "faster" && e.Result.Confidence >= 0.7)
//            {
//                gameSpeed *= 2;
//            }
//            else if (e.Result.Text.ToLower() == "slower" && e.Result.Confidence >= 0.7)
//            {
//                gameSpeed /= 2;
//            }
//            else if (e.Result.Text.ToLower() == "stop" && e.Result.Confidence >= 0.7)
//            {
//                Exit();
//            }
//            else if (e.Result.Text.ToLower() == "invert y" && e.Result.Confidence >= 0.7)
//            {
//                if (Paused == true)
//                {
//                    if (invertY == true)
//                    {
//                        invertY = false;
//                    }
//                    else
//                    {
//                        invertY = true;
//                    }
//                }
//            }
//            else if (e.Result.Text.ToLower() == "music volume" && e.Result.Confidence >= 0.55&& Paused==true)
//            {
//                musicVolumeSelected = true;
//                RHHome = RH;
//                LHHome = LH;
//            }
//            else if (e.Result.Text.ToLower() == "effects volume" && e.Result.Confidence >= 0.55 && Paused == true)
//            {
//                effectsVolumeSelected = true;
//                RHHome = RH;
//                LHHome = LH;
//            }
//            else if (e.Result.Text.ToLower() == "okay" && e.Result.Confidence >= 0.7)
//            {
//                musicVolumeSelected = false;
//                effectsVolumeSelected = false;
                
//            }


//            //if some speech has been recognized, test if its speech we want
//            //switch (e.Result.Text.ToLower())
//            //{
//            //    case "faster":
//            //        gameSpeed *= 2;
//            //        break;
//            //    case "slower":
//            //        gameSpeed /= 2;
//            //        break;
//            //    case "stop":
//            //        Exit();
//            //        break;

//            //    case "invert y":
//            //        if (Paused == true)
//            //        {
//            //            if (invertY == true)
//            //            {
//            //                invertY = false;
//            //            }
//            //            else
//            //            {
//            //                invertY = true;
//            //            }
//            //        }
//            //        break;
//            //}


//        }
//        //LAGGY
//        private void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
//        {
//            ColorImageFrame imageFrame = e.OpenColorImageFrame();

//            if (imageFrame != null && debugcamera == true)
//            {
//                byte[] pixelsFromFrame = new byte[imageFrame.PixelDataLength];
//                imageFrame.CopyPixelDataTo(pixelsFromFrame);
//                Color[] colors = new Color[imageFrame.Height * imageFrame.Width];
//                kinectRGB = new Texture2D(graphics.GraphicsDevice, imageFrame.Width, imageFrame.Height);

//                int index = 0;
//                for (int y = 0; y < imageFrame.Height; y++)
//                {
//                    for (int x = 0; x < imageFrame.Width; x++, index += 4)
//                    {
//                        colors[y * imageFrame.Width + x] = new Color(pixelsFromFrame[index + 2], pixelsFromFrame[index + 1], pixelsFromFrame[index]);
//                    }
//                }
//                kinectRGB.SetData(colors);

//            }
//        }

//        private void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
//        {
//            using (SkeletonFrame frame = e.OpenSkeletonFrame())
//            {
//                if (frame != null)
//                {
//                    Skeleton[] skeletonData = new Skeleton[frame.SkeletonArrayLength];
//                    frame.CopySkeletonDataTo(skeletonData);
//                    Skeleton playerSkeleton = (from s in skeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
//                    if (playerSkeleton != null)
//                    {

//                        Joint rightHand = playerSkeleton.Joints[JointType.HandRight].ScaleTo(640, 480, 1, 1);
//                        Joint leftHand = playerSkeleton.Joints[JointType.HandLeft].ScaleTo(640, 480, 1, 1);
//                        Joint head = playerSkeleton.Joints[JointType.Head].ScaleTo(640, 480, 1, 1);
//                        RH = new Vector3(rightHand.Position.X, rightHand.Position.Y, rightHand.Position.Z);
//                        LH = new Vector3(leftHand.Position.X, leftHand.Position.Y, leftHand.Position.Z);
//                        Head = new Vector3(head.Position.X, head.Position.Y, head.Position.Z);

                        

//                    }
//                }
//            }
//        }

//        #endregion  
 
//        #region Score Recording
//        /// <summary>
//        /// This method to record a score in a txt file and 
//        /// </summary>
//        /// <param name="x"></param>
//        private void RecordScore(int x)
//        {
//            writer = File.AppendText(path);
//            writer.WriteLine(targetScore.ToString());
//            writer.Close();

//        }
//        /// <summary>
//        /// Getting the highest score
//        /// </summary>
//        /// <returns>high score</returns>
//        private int GetHighScore()
//        {
//            string path = @"Score.txt";
//            reader = File.OpenText(path);
//            int highScore = 0;
//            while (reader.Peek() != -1)
//            {
//                int score = int.Parse(reader.ReadLine());
//                if (score > highScore)
//                {
//                    highScore = score;
//                }
//            }
//            reader.Close();
//            return highScore;
//        }
    
//    #endregion


//        //  a handy little function that gives a random float between two
//        // values. This will be used in several places in the sample, in particilar in
//        // ParticleSystem.InitializeParticle.
//        internal static float RandomBetween(float min, float max)
//        {
//            return min + (float)rnd.NextDouble() * (max - min);
//        }


//    }




//}


